package com.hbusa.cotroller.type;


import com.hbusa.dto.TbCategory;
import com.hbusa.service.CategoryService;
import com.hbusa.service.service.impl.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/doCategoryFindAll")
public class CategoryFindAll extends HttpServlet {
//
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");


//        String cat_id = req.getParameter("cat_id");
//        String cat_name = req.getParameter("cat_name");
//
//        System.out.println(cat_name);
//        System.out.println(cat_id);


        CategoryService categoryService = new CategoryServiceImpl();
        //https://blog.csdn.net/dl0246/article/details/80428299?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164054738616780264074964%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164054738616780264074964&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-80428299.pc_search_insert_es_download&utm_term=jstl+servlet&spm=1018.2226.3001.4187

        ArrayList<TbCategory> categoryArrayList = categoryService.doFindAll();


        TbCategory category = new TbCategory();
//        category.setCa
        HttpSession session = req.getSession();
        session.setAttribute("cattt",categoryArrayList);

        resp.sendRedirect("admin/categoryFindAll.jsp");

//        for (TbCategory tbCategory : categoryArrayList) {
//            System.out.println(tbCategory.getCatName());
//            System.out.println(tbCategory.getCatId());
//        }



    }
}
